jfxfandomcom-20200214-history
FAQ
General Questions See also the Frequently Encountered Issues page. What is JavaFX? "JavaFX Script is a declarative, statically typed programming language. It has first-class functions, declarative syntax, list-comprehensions, and incremental dependency-based evaluation." JavaFX Script provides a declarative, non-procedural syntax for diverse operations such as creating 2D animations, setting properties or declaring binding dependencies between model and view objects (to name a few). What does 'declarative syntax' mean? Unlike most languages which rely on procedures and explicit code in order to update relationships between variables or properties a 'declarative' language allows for values to be declared with respect to other languages. An example in JavaFX would be "var a : Number = bind model.attrib/2;" Whenever the value of model.attrib changed then the value of a is automatically and transparently updated without any procedural action. This is particularly useful for binding dependencies between model and view objects and with controlling the behaviour of GUIs. What does 'list-comprehensions' mean? List comprehension is the language level support to create and manipulate lists in various ways such as: * var nums = 1,2,3,4; * var nums2 = 1..4; //same as above * insert 10,11 into nums2; // Add at end * delete 4 from nums2; // Remove item (content, not index) * delete nums22..3; // Remove a range of indices * var numsGreaterThanTwo = numsx > 2; * var numsLessThanFour = for (n in nums where n < 4) n; What is "incremental dependency-based evaluation"? Attribute values can be declared to be dependent on (bound to) expressions involving other attributes. Thus, when a referenced attribute changes its value all attributes directly or indirectly dependent on it will change their values accordingly with no intervening procedural logic. This is similar to the way formula cells in a spreadsheet change their values whenever one or more cells they depend upon change their values. This is especially useful for GUI development where maintaining model and view attributes in sync usually requires complex procedural logic. What is the licensing model? From the Mailing list The current release of JavaFX is under an evaluation license and cannot be redistributed. You can certainly distribute your own JavaFX-based applications without bundling JavaFX, and just point users to the openjfx.org site so they can download the JavaFx binaries themselves. Note, however, that because the JavaFx code is early access under an evaluation license, it isn't licensed for commercial uses. As we develop a commercial product quality release, I will be sure to keep you updated on this alias. Update Nandini Ramani, 25-May-2007, openjfx user ML I would like to reiterate that it is perfectly fine to distribute your JavaFX applications, in fact we encourage it. I was just pointing out that it is not yet ready for commercial use. So, Augusto and others are welcome to distribute their applications. Unlike other proprietary companies, we at Sun really do believe in open source and community involvement. I am sorry we do not have a licensing model in place yet, but I assure you that we are working on it and I will keep you all posted as soon as we have one in place. > Does Sun have a timeline for a commercial quality product release of > JavaFX? > > Does Sun have any guidance as to what license the JavaFX Runtime will > be distributed under? As I mentioned above, we don't have a date yet, but we will have one soon. > Is the JavaFX Runtime the same thing as the JavaFX Script which is to > be "open sourced" as per the FAQ? Yes, it is and the runtime will be open sourced. What is the relation between JavaFX and ... ... F3 F3, 'F'orm 'F'ollows 'F'unction, is the former name for the JavaFX platform. ... Java JavaFX is a JSR-223-compliant scripting language. It can use Java classes and can be invoked from Java classes. ... SVG From the mailing lists: > I wonder why ave you decided to develop own scripting language JavaFX > script instead of using SVG/SMIL based technologies? Apache batic > project already has good support for SVG/SMIL including animation and > scripting capabilities. Isn't is simpler and better to develop something > based on already existing open standarts like SVG? SVG is not a programming language; it's a data description language. XML syntax is horrible for a programming language. (It has some issues for data description languages - though also some advantages.) > Are there any plans to use SVG? I don't think there are any plans to use SVG directly. However, SVG interoperability/compatibility is desirable. To some extent we already have that, since both are derived from the old PostScript and Java2d vector graphics models. Still, there may be some incompatibilities that may be worth looking at. Chris Oliver has written about a SVG-to-F3 transformer. Update: JavaFX has a SVGPath class and tools to convert SVG to JavaFX syntax. ... Swing JavaFX is a new way of writing GUI applications, without knowing the Swing architecture and the Java language (although it helps to know the latter). JavaFX provides a way to integrate Swing components to its UI. ... JavaScript? The only real similarity is that both JavaScript and JavaFX are scripting languages compliant with JSR-223. On the browser, JavaFX applets can communicate with JavaScript on the same page. ... AJAX? Ajax is the term used to denote the use of JavaScript and asynchronous updating from a server, in Web browsers. The only relation to JavaFX is that both are UI-related technologies. But they are for completely different languages and environments. ... Savaje OS? Apparently, Sun is planning on using its purchase of the Savaje phone OS and JVM to deliver JavaFX Mobile, that is capable of running JavaFX Scripts. It will compete in the same space as Windows Mobile and, to some extent, Flash Lite. Can I use JavaFX to program 3D applications? Is it compatible with VRML or X3D standards or libraries such as Xj3D? There is no reason you cannot -- JavaFX can interoperate with any library. That being said, there is no special syntax in JavaFX to take advantage of these libraries like there is for Java2d constructs. One could make JavaFX wrappers for a library to achieve this, however. Is JavaFX an RCP (Rich Client Platform)? Yes JavaFX can be used for RCP as well as RIA (Rich Internet Applications) How JavaFX can be used for eclipse RCP, it possible to show some code snippet? Can I make a Web application with JavaFX? JavaFX can be used to write the front end, the view or the user interface of the Web application. Is JavaFX going to replace JSF and JSP in Java EE? No, JSF and JSP can be used to make pure Web applications (usable by any HTTP client that supports HTML), while JavaFX needs a JVM on client side and its library files. If you want to have a rich client and you can install plugin on client side, JavaFX provides a good Java based alternative to Flash based Adobe Flex and .NET based Microsoft Silverlight technologies for rich internet applications (RIA). A typical scenario is applications that are developed to run on local intranet of a company. Do I need a server for JavaFX? JavaFX is scripting language with a GUI focus; it is primarily used for desktop applications. No server is required by JavaFX except to provide the jar file(s), of course. What is needed on a machine to run JavaFX applications? You will need Java5 + a JSR-223 implementation + the JavaFX libraries. Or, you need Java6 + JavaFX. It is possible to web-start or applet-start JavaFX, as well. How to host a JavaFX application on Web server? The answer is largely the same as for the question: What is needed on a machine to run JavaFX applications? Where can I find ... for JavaFX? binary distribution source code The source code section of the downloads page of the OpenFX project website. documentations Tutorials and other training materials * Tutorials in this wiki * The OpenJFX official page has tutorials as well. Sample Applications What are available tool supports for JavaFX? Netbeans Eclipse Ant Files for use with Eclipse. JFXBuilder http://www.reportmill.com/jfx/ - not exactly a builder, but a quick conversion from the report writer application See also JFXBuilder Is a compiler available for JavaFX? Yes, it is part of the JavaFX SDK. See also JavaFX Compiler. Programming Questions What primitive data types are available? See JavaFX Primitive Data Types How do I concatenate strings? The + operator doesn't work! In a nutshell: var hallo = "Hallo"; var world = "world"; var string = "{hallo} {world}!"; Or: var string = "Hallo ".concat("world"); See String Concatenation How do I convert a String to a Number? There is currently no direct way, but the following works: var value = new DecimalFormat("0").parse(someString); I can suggest this way it is more convenient: var any=Integer.parseInt(String); How do I format a String like with printf()? println "cost: {%.2f number} $"; See Sergey Malenkov, "How to format a string?", 26-Jan-2009 How do I bind a TextField's value to a Number attribute? Use a bind: var total = 10 TextField { value: bind total ... } Also, using format may be useful: value: bind "{total format as <<#,##0>>}" How do I set up JavaFX for Java Web Start? See the JNLP tutorial. Note that the current license somewhat restricts redistribution (see What is the licencing model? above). If you are using NetBeans IDE: right-click the project name --> properties --> Run --> (and select) Web Start Execution. How do I refer to a fully-qualified java class? Fully qualified Java class names must be enclosed in French quotes << >>. How do I access inner classes and interfaces? At this time you have to use the compiled name of inner classes. For example, import java.util.Map.Entry has to be represented as import java.util.Map$Entry in JavaFX. Also note that to reference the inner class, you will have to continue to use the Outer$Inner syntax. To get around this, you can change the import statement thusly: import java.util.Map$Entry as Entry Can I use Java 5 enumerations? Yes. You can refer to them in the following way: import java.util.management.MemoryType; // an Enum var value = HEAP:MemoryType; // value of the Enum... // HEAP is the enum constant name inside of MemoryType var allValues = MemoryType.values(); // creates a JavaFX array of all enums How can I easily use custom Swing components in JavaFX? See Use any swing component. How can I easily make a custom reusable UI component (e.g. a Panel) in JavaFX? If you want to use a custom Swing component, see the previous question. To make a reusable JFX visual class, you should extend either CompositeWidget (for buttons, menus, trees, etc) or CompositeNode (for custom graphics objects). Override the composeWidget() or composeNode() methods to return the particular UI component you wish. See Custom Widgets and Nodes for examples of custom Node objects. Why are some of my .fx files not getting reloaded in JavaFX Pad? From the mailing list: Sorry, JavaFXPad is very limited at the moment. It doesn't detect changes to external files. To make it "see" your changes you'd have to open the changed file in JavaFXPad, and then reopen your original file again. What is the difference between Nodes and Widgets? Nodes are graphical entities that generally correspond to Java2D constructs and operations -- Rectangles, circles, text, lines, etc. Widgets are the equivalent of Swing components -- menus, tables, trees, buttons, etc. How do you embed Nodes in Widgets and vice-versa? A Canvas is a Widget that contains Nodes. A View is a Node that contains Widgets. Using these two classes, a component hierarchy can bridge the gap between Widget and Node multiple times. Does JavaFX Script provide magic constants like __FILE__? Yes, see Magic Constants for a list of supported magic constants in JavaFX Script. How do I refer to "this" while declaring a variable? See JavaFX's version of "this". What are the reserved words in JavaFX? See Reserved Words. How can I add JFX components to an existing Swing application? There are two paths to follow, nodes and widgets (see above for the difference). If your top-level component is a Node, then wrap it in a canvas and return the result of getComponent() at the end of your script: return Canvas { content: myNode }.getComponent(); If you top-level component is a widget, you can skip wrapping in a canvas and just call getComponent() directly: return myWidget.getComponent(); To see how to get a return value from a script, see the bottom of the java files at Programmatically invoking a script.